/*
 * Copyright (c) zhg2yqq.com Corp.
 * All Rights Reserved.
 */
package com.zhg2yqq.wheels.mvc.base;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhg2yqq.wheels.mvc.wrapper.EncryptLambdaQueryWrapper;
import com.zhg2yqq.wheels.mvc.wrapper.EncryptLambdaUpdateWrapper;
import com.zhg2yqq.wheels.mvc.wrapper.EncryptQueryWrapper;
import com.zhg2yqq.wheels.mvc.wrapper.EncryptUpdateWrapper;

import java.io.Serializable;
import java.util.Collection;

/**
 * @author zhg2yqq, 2022年12月3日
 * @version zhg2yqq v1.0
 */
public interface IBaseService<T> extends IService<T> {
    default QueryWrapper<T> queryWrapper() {
        return new EncryptQueryWrapper<>();
    }

    default LambdaQueryWrapper<T> lambdaQueryWrapper() {
        return new EncryptLambdaQueryWrapper<>(getEntityClass());
    }

    default UpdateWrapper<T> updateWrapper() {
        return new EncryptUpdateWrapper<>();
    }

    default LambdaUpdateWrapper<T> lambdaUpdateWrapper() {
        return new EncryptLambdaUpdateWrapper<>(getEntityClass());
    }

    /**
     * 类型转化
     *
     * @param source 源
     * @return 目标
     */
    default T transfer(Object source, String... ignoreFields) {
        return transfer(source, getEntityClass(), ignoreFields);
    }

    /**
     * 类型转化
     *
     * @param source 源
     * @return 目标
     */
    default <O> O transfer(Object source, Class<O> targetClass, String... ignoreFields) {
        if (source == null) {
            return null;
        }
        return BeanUtil.copyProperties(source, targetClass, ignoreFields);
    }

    default void saveCheck(T entity) {

    }

    default void updateCheck(T entity) {

    }

    default void removeCheck(T entity) {

    }

    @Override
    @Deprecated
    default boolean removeByIds(Collection<?> list) {
        return IService.super.removeByIds(list);
    }

    @Override
    @Deprecated
    default boolean removeById(Serializable id, boolean useFill) {
        return IService.super.removeById(id, useFill);
    }

    @Override
    @Deprecated
    default boolean removeById(T entity) {
        return IService.super.removeById(entity);
    }

    @Override
    @Deprecated
    default boolean removeByIds(Collection<?> list, boolean useFill) {
        return IService.super.removeByIds(list, useFill);
    }

    @Override
    @Deprecated
    default boolean removeBatchByIds(Collection<?> list, boolean useFill) {
        return IService.super.removeBatchByIds(list, useFill);
    }

    @Override
    @Deprecated
    default boolean removeBatchByIds(Collection<?> list, int batchSize) {
        return IService.super.removeBatchByIds(list, batchSize);
    }

    @Override
    @Deprecated
    default boolean removeBatchByIds(Collection<?> list, int batchSize, boolean useFill) {
        return IService.super.removeBatchByIds(list, batchSize, useFill);
    }
}
